package tankattack.sprites;

import gamepack.*;
import java.awt.*;
import java.util.Vector;

/** @author Somanath
*/

// Dependency : None
public class FlexiBrick extends Sprite {

static {
	   //System.out.println("#########################  Flexi.java Compiled ##########################");
	   }

    // <Data name="spawnformat"> x=%d,y=%d # mx=%f:0, ax=%f:0, my=%f:0 , ay=%f:0, mw=%f:0 , aw=%f:10 , mh=%f:0, ah=%f:10 " </Data>
	
	public FlexiBrick() {		
		
		setAttribute( "BLOCK" );
		SpriteArgs sa = Sprite.getArgs();
		double mx = sa.getAsDouble("mx");
		double my = sa.getAsDouble("my");
		double mw = sa.getAsDouble("mw");
		double mh = sa.getAsDouble("mh");
		
		double ax = sa.getAsDouble("ax");
		double ay = sa.getAsDouble("ay");
		double aw = sa.getAsDouble("aw");
		double ah = sa.getAsDouble("ah");
	
		Room room = World.currentWorld.curRoom;
		int w = room.getWidth();
		int h = room.getHeight();
		Image aa = room.img;
		
		x = (int) (mx * w + ax);
		y = (int) (my * h + ay);
		int width = (int) (mw * w + aw);
		int height = (int) (mh * h + ah);
		
		//int width = Integer.parseInt( sa.strMap.get("width").toString() );
		//int height = Integer.parseInt( sa.strMap.get("height").toString()  );
		// Create the picture of the Flexibrick at runtime.
		Color fillColor = Color.gray;
		Color borderColor = Color.black;
		Image img = Application.createImage(width,height,fillColor);
		Graphics g = img.getGraphics();
		if( g == null )	throw new RuntimeException(" g == null in flexibrick ");
		g.setColor(borderColor);
		g.drawRect(0,0,width-1,height-1);

        // Store the image data in attribute 'res'
		res = new Resource();   // This is set to null in base class Sprite
		res.img = new CImage[1][1];
		res.img[0][0] = new CImage(img,0,0,new Rectangle(0,0,width,height));

		startSprite();
	}
	
}